package net.muchine.test.spring.data.example.core;

import java.net.UnknownHostException;

import net.muchine.test.spring.data.example.test.Tester;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;

import com.mongodb.Mongo;

public class MongoJavaApp {
	private static final Log log = LogFactory.getLog(MongoJavaApp.class);
	
	public MongoTemplate getTemplate(String database) throws UnknownHostException {
		return new MongoTemplate(new Mongo(), database);
	}
	
	public MongoTemplate getTemplateByDBFactory(String database) throws UnknownHostException {
		return new MongoTemplate(new SimpleMongoDbFactory(new Mongo(), database));
	}
	
	public static void main(String[] args) throws Exception {
		MongoJavaApp app = new MongoJavaApp();
		String database = "spring";
		
		MongoOperations mongo = app.getTemplate(database);
		Tester tester = new Tester(mongo);
		tester.test();
		
		mongo = app.getTemplateByDBFactory(database);
		tester = new Tester(mongo);
		tester.test();
	}
}
